package com.qq.BFMRSE.indexTree;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

import com.qq.BFMRSE.entity.BloomFilter;
import com.qq.BFMRSE.entity.indexTreeNode;



public class buildIndexTreeHelper {
	public static Queue<indexTreeNode> getallLeafIndexTree(List<String> fidList)
	{
		Queue<indexTreeNode> resultQueue=new LinkedBlockingQueue<indexTreeNode>();
		Iterator<String> iterator=fidList.iterator();
		while(iterator.hasNext())
		{
			String fid=iterator.next();
			indexTreeNode tempIndexNode=getNewLeafIndexTree(fid);
			resultQueue.add(tempIndexNode);
		}
		return resultQueue;
	}

	public static indexTreeNode getNewLeafIndexTree(String fid)
	{
		indexTreeNode resultNode=new indexTreeNode();
		//List<String> wordList=DBHelper.getWordList(fid);
		List<String> wordList=new ArrayList<>();
	    Iterator<String>iterator=wordList.iterator();
	    BloomFilter bf=new BloomFilter();
	    while (iterator.hasNext()) {
			String tempWord=iterator.next();
			bf.addValue(tempWord);
		}
	    resultNode.setBf(bf);
	    resultNode.setFID(fid);
		return resultNode;
	}

	public static List<indexTreeNode> getAllBuildTreeNode(indexTreeNode root)
	{
		List<indexTreeNode> resultList=new ArrayList<indexTreeNode>();
		Queue<indexTreeNode> queue=new LinkedBlockingQueue<indexTreeNode>();
		indexTreeNode currNode=root;
		if(currNode!=null)
		{
			queue.add(currNode);
		}
		while(!queue.isEmpty())
		{
			indexTreeNode tempNode=queue.peek();
			resultList.add(tempNode);
			if(tempNode.getLeft()!=null)
			{
				queue.add(tempNode.getLeft());
			}
			if(tempNode.getRight()!=null)
			{
				queue.add(tempNode.getRight());
			}
			
		}
		return resultList;
		
	}

	
}
